<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Profile extends MY_Controller {

	function __construct()
	{
		parent::__construct();
	}
	function index()
	{
		if ($this->uri->segment(2) === FALSE)
		{
			$this->check_logged_in();		
			$this->userprofile($this->current_user_name());
		}
		else if($this->uri->segment(2) == 'org')
        {
            $this->org();
        }
        else
		{
			$this->userprofile($this->uri->segment(2));
		}
	}
	
	function userprofile($username = FALSE)
	{
		$own_page = FALSE;
	
		if($username === FALSE)
		{
			$this->index();
		}		
		
		$data['text'] = 'This page should show details of the user. If user ID is a third parameter, that user will be show, if there is no third parameter, then currently logged user with options to update. Of course, list of all (or most important) articles from the users should be here.';

		if(is_numeric($username))
		{
			$data['user'] = OxUser::from_id($username);
		}
		else 
		{
			$data['user'] = OxUser::from_username($username);
		}	
	
    	if($data['user']->iduser == $this->current_user_id())
		{
			$this->show_own_profile();
			return;
		}
		
	    $b = array ();
        $b[] = array ("style"=>"background:#aacccc", "title"=>"Connect with the author...", 
				        "text"=>'You can contribute to writer\'s areticles in many ways. Read more about <a href="'.site_url('info/10').'">Oximity Community.</a>');
		$b[] = array ("box_view"=>"article",
                        "style"=>"", "title"=>"News Flash", 
				        "article"=>OxArticle::get_random_article());
        $b[] = array ("box_view"=>"article",
                        "style"=>"background:#eecccc", "title"=>"Featured Article", 
				        "article"=>OxArticle::get_random_article());
        $b[] = array ("box_view"=>"article",
                        "style"=>"", "title"=>"Local Flash", 
				        "articles"=>OxArticle::get_random_article());
		
        $data2['boxes'] = $b;


		$this->ShowHeader();
		$this->load->view('person_profile', $data);
		$this->load->view('box_frame', $data2);
		$this->ShowFooter();
	}
	
	function show_own_profile()
	{
		$data['user'] = OxUser::from_id($this->current_user_id());
		$data['actions'] = array();
		
		$data['action_pending'] = FALSE;
		
		$this->ShowHeader();
		$this->load->view('own_profile', $data);
		$this->ShowFooter();
	}
	function org()
	{
		$data['org'] = OxOrganization::from_id($this->uri->segment(3));

        $b = array ();
        $b[] = array ("style"=>"background:#aacccc", "title"=>"How to learn more about this organization...", 
				        "text"=>'You can learn more about the organization by visiting <a>their webiste at www.organization.com</a> or '
                              .' by following their stories by subscribing. Learn more about <a href="'.site_url('info/10').'">Oximity Community.</a>');
		$b[] = array ("box_view"=>"article",
                        "style"=>"", "title"=>"News Flash", 
				        "article"=>OxArticle::get_random_article());
        $b[] = array ("box_view"=>"article",
                        "style"=>"background:#eecccc", "title"=>"Featured Article", 
				        "article"=>OxArticle::get_random_article());
        $b[] = array ("box_view"=>"article",
                        "style"=>"", "title"=>"Local Flash", 
				        "articles"=>OxArticle::get_random_article());
		
        $data2['boxes'] = $b;
	
		$this->ShowHeader();
		$this->load->view('organization_profile', $data);
		$this->load->view('box_frame', $data2);
		$this->ShowFooter();
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */